<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>test</title>
</head>

<body>
  <div id="app">
    <input onblur="fmt(event)">
    <p id="content"></p>
  </div>
  <script>
    function fmt(ev) {
      console.log("value:", ev.target.value)

      let reg = new RegExp(ev.target.value)
      
      // let reg = regx(ev.target.value)
      console.log(ev.target.value === "\\\\d\\\\d") // true
      console.log(ev.target.value)
      console.log("reg", reg.toString())

      let reg2 = new RegExp(String(ev.target.value))
      console.log("reg2:", reg2.toString())

      let reg3 = "\\d\\d"
      reg3 = new RegExp(reg3)
      console.log("reg3:", reg3.toString())

      let reg4 = `\\d\\d`
      reg4 = new RegExp(reg4)
      console.log("reg4:", reg4.toString())

      // js 字符串的转义发生在
      // 1. 字面量赋值字符串，例如： let str = "\\d", 实际得到的值为： "\d"
      // 2. json 将对象转换成字符串的时候

      let str = {
        str: "\\\\"
      }
      console.log(str.str)
      console.log(JSON.stringify(str))
    }
  </script>
</body>
